package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.InterveneTemplateApi;
import com.als.healthymananger.entity.InterveneTemplate;
import com.als.healthymananger.service.InterveneTemplateService;
import com.als.healthymananger.service.IntervenesService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/intervence/template")
public class InterveneTemplateController implements InterveneTemplateApi {
    @Autowired
    private InterveneTemplateService interveneTemplateService;

    @Override
    public RespBean createInterveneTemplates(InterveneTemplate interveneTemplate) {
        return interveneTemplateService.save(interveneTemplate)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteInterveneTemplates(int interveneTemplateId) {
        return interveneTemplateService.removeById(interveneTemplateId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateInterveneTemplates(int interveneTemplateId, InterveneTemplate interveneTemplate) {
        return interveneTemplateService.updateById(interveneTemplate)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getInterveneTemplates(int interveneTemplateId) {
        InterveneTemplate template = interveneTemplateService.getById(interveneTemplateId);
        return template == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功", template);
    }
}
